<?php
class Login extends CI_Controller {

	 public function __construct()
       {
            parent::__construct();
        	$this->output->enable_profiler(PROFILER);
       }	


	public function index() {

		$data['main_content'] = "admin/login/login_form";
		$this -> load -> view("includes/login/template", $data);
	}

	function validate_credentials() {
		
		$this->load->model("usermodel");
		
		$query = $this -> usermodel -> validate();

		if (count($query)>1)// if the user's credentials validated...
		{
			$data = array('username' => $query['username'], 'user_id' => $query['id'],'is_logged_in' => true);
			$this -> session -> set_userdata($data);
			redirect('user/index');
		} else// incorrect username or password
		{
			$this -> session -> set_flashdata('message', array('title' => 'Access denied', 'content' => 'You are not allowed to access the admin section of this site, please contact the administrator', 'type' => 'error'));
			redirect('login/index');
		}
	}

	function logout() {
		$this -> session -> sess_destroy();
		redirect('login/index');
	}

}
?>